/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
  let n = prices.length
  let max = 0
  
  for (let i = 1; i < n; i++) {
    // 找到i之前的最小值
    max = Math.max(max,prices[i]-prices[i-1])
    prices[i] = Math.min(prices[i],prices[i-1])
  }
  return max
};

var prices = [7, 1, 5, 3, 6, 4]
console.log(maxProfit(prices))
